package com.itheima.boot.domain;

import lombok.Getter;

@Getter
public class R<T> {
    private Integer code;
    private String msg;
    private T data;

    public R(Integer code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public R(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
        this.data = null;
    }

    public static <T> R<T> success(T data){
        return new R<T>(200,"success",data);
    }

    public static <T> R<T> success(String msg){
        return new R<T>(200,msg,null);
    }

    public static <T> R<T> success(){
        return new R<T>(200,"success",null);
    }

    public static <T> R<T> error(){
        return new R<T>(500,"error",null);
    }

    public static <T> R<T> error(String msg){
        return new R<T>(500,msg,null);
    }

    public static <T> R<T> error(Integer code,String msg){
        return new R<T>(code,msg,null);
    }
}
